home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Adobe Graphics & Publishing SDK 1996 December
/
Adobe Graphics & Publishing SDK 1996 December.iso
/
pc
/
pm65sdk
/
sourcecode
/
pagemakerclasslibrary
/
lowlevel
/
pquery.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-05
|
7KB
|
252 lines
/*
*--- PQuery.cpp ----------------------------------------------------------
* Copyright (c) 1995-96 Adobe Systems Incorporated. All rights reserved.
* Created on Thu, Oct 12, 1995 @ 9:47 PM by Paul Ferguson.
*
* Description: For notes about this class, refer to the
* header file PQuery.h
*-------------------------------------------------------------------------
*/
#include "PQuery.h"
#include "PRequestBuf.h"
#include "CIBasic.h"
#include "CIInterfaceManager.h"
#include "PMInterfaceIDs.h"
extern PMMessage * gPMMessage;
#include "PMCQErrs.h"
/*
*--- PQuery constructor ---------------------------------------
* Issue a PageMaker query that returns a single short value.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, short &aShort)
{
ClearRequestBlock();
itsPB->replyData = &aShort;
itsPB->replySize = sizeof(short);
itsPB->replyStyle = kXRSPointer;
itsPB->replyUnits = 0;
DoQuery(op);
}
/*
*--- PQuery constructor ---------------------------------------
* Issue a PageMaker query that returns a single long value.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, long &aLong)
{
ClearRequestBlock();
itsPB->replyData = &aLong;
itsPB->replySize = sizeof(long);
itsPB->replyStyle = kXRSPointer;
itsPB->replyUnits = 0;
DoQuery(op);
}
/*
*--- PQuery constructor ---------------------------------------
* Issue a PageMaker query that returns a handle allocated
* by PageMaker.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, PMHandle &aHandle) throw (PMErr)
{
itsPB->replyData = NULL;
itsPB->replySize = 0L;
itsPB->replyStyle = kXRSHandle;
ClearRequestBlock();
DoQuery(op);
aHandle = (PMHandle) itsPB->replyData;
if (aHandle == NULL) // a null return handle is definitely a problem...
throw CQ_FAILURE;
}
/*
*--- PQuery constructor ---------------------------------------
* This constructor is for more efficient access when the
* size of the returned query is known ahead of time.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, void * theBuf, size_t len)
{
ClearRequestBlock();
itsPB->replyData = theBuf;
itsPB->replySize = len;
itsPB->replyStyle = kXRSPointer;
itsPB->replyUnits = 0;
DoQuery(op);
}
/*
*--- PQuery constructor ---------------------------------------
* Execute a query with a PRequestBuf object.
*
* Note that this always allocates a heap memory block to return
* the query result. You could overload DoQuery with functions
* optimized for queries with request buffers and returning
* a fixed length amount of information.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, PRequestBuf& request, short & aShort)
{
SetRequestBlock(request);
itsPB->replyData = &aShort;
itsPB->replySize = sizeof(short);
itsPB->replyStyle = kXRSPointer;
itsPB->replyUnits = 0;
DoQuery(op);
}
/*
*--- PQuery constructor ---------------------------------------
* Execute a query with a PRequestBuf object.
*
* Note that this always allocates a heap memory block to return
* the query result. You could overload DoQuery with functions
* optimized for queries with request buffers and returning
* a fixed length amount of information.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, PRequestBuf& request, long & aLong)
{
SetRequestBlock(request);
itsPB->replyData = &aLong;
itsPB->replySize = sizeof(long);
itsPB->replyStyle = kXRSPointer;
itsPB->replyUnits = 0;
DoQuery(op);
}
/*
*--- PQuery constructor ---------------------------------------
* Execute a query with a PRequestBuf object.
*
* Note that this always allocates a heap memory block to return
* the query result. You could overload DoQuery with functions
* optimized for queries with request buffers and returning
* a fixed length amount of information.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, PRequestBuf& request, PMHandle & aHandle)
{
SetRequestBlock(request);
itsPB->replyData = NULL;
itsPB->replySize = 0;
itsPB->replyStyle = kXRSHandle;
itsPB->replyUnits = 0;
DoQuery(op);
aHandle = (PMHandle) itsPB->replyData;
if (aHandle == NULL) // a null return handle is definitely a problem...
throw CQ_FAILURE;
}
/*
*--- PQuery constructor ---------------------------------------
* This constructor is for more efficient access when the size
* of the returned query is known ahead of time.
*--------------------------------------------------------------
*/
PQuery::PQuery(ePMQuery op, PRequestBuf& request, void * theBuf, size_t len)
{
SetRequestBlock(request);
itsPB->replyData = theBuf;
itsPB->replySize = len;
itsPB->replyStyle = kXRSPointer;
itsPB->replyUnits = 0;
DoQuery(op);
}
/*
*--- DoQuery --------------------------------------------------
* Set opcode and issue callback. Issue private call into
* PCallback superclass.
*--------------------------------------------------------------
*/
void PQuery::DoQuery(ePMQuery op) throw (PMErr)
{
itsPB->opCode = op;
try
{
CallPageMaker();
}
catch (PMErr err) // If a handle was allocated by PageMaker, should free it.
{
if ( (itsPB->replyStyle == kXRSHandle) && (itsPB->replyData != NULL) )
{
CIBasic * basicInterface;
gPMMessage->pInterfaceMgr->AcquirePMInterface((unsigned long)PMIID_BASIC, (void **) &basicInterface);
basicInterface->PMMemFree(itsPB->replyData);
itsPB->replyData = NULL;
gPMMessage->pInterfaceMgr->ReleasePMInterface(basicInterface);
}
throw; // rethrow exception
}
}
/*
*--- SetRequestBlock ------------------------------------------
* Does what it says...
*--------------------------------------------------------------
*/
void PQuery::SetRequestBlock(PRequestBuf& request)
{
itsPB->requestData = (const char *) request;
itsPB->requestSize = request.Size();
itsPB->requestStyle = kXRSPointer;
itsPB->requestUnits = 0;
}
/*
*--- ClearRequestBlock ----------------------------------------
* Does what it says...
*--------------------------------------------------------------
*/
void PQuery::ClearRequestBlock()
{
itsPB->requestData = NULL;
itsPB->requestSize = 0L;
itsPB->requestStyle = 0;
itsPB->requestUnits = 0;
}
// end of PQuery.cpp